﻿/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is tyzoh.jp code.
 *
 * The Initial Developer of the Original Code is Kazutaka Kurihara.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Qurihara.QBasic
{
	/// <summary>
	/// TextEntryForm の概要の説明です。
	/// </summary>
	public class TextEntryForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label labelQuestion;
		private System.Windows.Forms.Button buttonCancel;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.TextBox textBox;
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TextEntryForm(string title, string question)
		{
			//
			// Windows フォーム デザイナ サポートに必要です。
			//
			InitializeComponent();

			this.Text = title;
			this.labelQuestion.Text = question;
		}
		public string OutputText
		{
			get{return this.textBox.Text;}
			set{this.textBox.Text = value;}
		}

		/// <summary>
		/// 使用されているリソースに後処理を実行します。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows フォーム デザイナで生成されたコード 
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		private void InitializeComponent()
		{
			this.labelQuestion = new System.Windows.Forms.Label();
			this.textBox = new System.Windows.Forms.TextBox();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.buttonOK = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// labelQuestion
			// 
			this.labelQuestion.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.labelQuestion.Location = new System.Drawing.Point(16, 16);
			this.labelQuestion.Name = "labelQuestion";
			this.labelQuestion.Size = new System.Drawing.Size(432, 48);
			this.labelQuestion.TabIndex = 0;
			this.labelQuestion.Text = "新しいリストの名前を入力してください。";
			// 
			// textBox
			// 
			this.textBox.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.textBox.Location = new System.Drawing.Point(16, 72);
			this.textBox.Name = "textBox";
			this.textBox.Size = new System.Drawing.Size(432, 34);
			this.textBox.TabIndex = 3;
			this.textBox.Text = "name";
			this.textBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyUp);
			// 
			// buttonCancel
			// 
			this.buttonCancel.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.buttonCancel.Location = new System.Drawing.Point(320, 136);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.Size = new System.Drawing.Size(128, 40);
			this.buttonCancel.TabIndex = 4;
			this.buttonCancel.Text = "キャンセル";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// buttonOK
			// 
			this.buttonOK.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
			this.buttonOK.Location = new System.Drawing.Point(172, 136);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.Size = new System.Drawing.Size(128, 40);
			this.buttonOK.TabIndex = 5;
			this.buttonOK.Text = "ＯＫ";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// TextEntryForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(472, 188);
			this.Controls.Add(this.buttonOK);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.textBox);
			this.Controls.Add(this.labelQuestion);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "TextEntryForm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "新しい視点リストの作成";
			this.TopMost = true;
			this.Closing += new System.ComponentModel.CancelEventHandler(this.TextEntryForm_Closing);
			this.Load += new System.EventHandler(this.TextEntryForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private bool clicked = false;
		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.OK;
			clicked = true;
			this.Close();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			clicked = true;
			this.Close();
		}

		private void TextEntryForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if (!clicked)
				DialogResult = DialogResult.Cancel;
		}

		private void textBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Enter)
			{
				DialogResult = DialogResult.OK;
				clicked = true;
				this.Close();
			}
		}

		private void TextEntryForm_Load(object sender, System.EventArgs e)
		{
			//this.Activate();
			this.textBox.Focus();
		}
	}
}
